package dgut.haitaobao.controller;

import dgut.haitaobao.entry.IndexImg;
import dgut.haitaobao.service.CategoryService;
import dgut.haitaobao.service.IndexImgService;
import dgut.haitaobao.service.ProductService;
import dgut.haitaobao.util.response.HttpResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/*首页controller*/
@RestController
@CrossOrigin
@RequestMapping("/index")
public class IndexController {
    @Autowired
    private IndexImgService indexImgService;

    @Autowired
    private CategoryService categoryService;

    @Autowired
    private ProductService productService;
    
    /*获取轮播图相关数据*/
    @GetMapping("/getIndexImgList")
    public HttpResponse getIndexImgList(){
        List<IndexImg> indexImgList = indexImgService.getIndexImgList();
        if (CollectionUtils.isEmpty(indexImgList)){
            return HttpResponse.error("获取轮播图失败");
        }else {
            return HttpResponse.success(indexImgList);
        }
    }
    
    //获取分类层级
    @GetMapping("/getCategories")
    public HttpResponse getCategories(){
        return categoryService.listCategories();
    }

    //获得商品推荐的信息
    @GetMapping("/getRecommendProductList")
    public HttpResponse getRecommendProductList(){
        return productService.getRecommendProductList();
    }

    //获得各一级分类商品下的销售量最高6个商品
    @GetMapping("/getMaxSoldNumProducts")
    public HttpResponse getMaxSoldNumProducts(){
        return categoryService.getMaxSoldNumProducts();
    }
}
